<template>
     <table class="my-table">
      <thead>
        <tr>
          <slot name="head"></slot>
          <!-- 上下两个slot插槽，是为了提高组件的复用性，
          避免出现两个插槽混乱，分别命名以区别 -->
        </tr>
      </thead>
      <tbody>
        <!-- 父传子，传入数组，循环进行渲染 -->
        <tr v-for="item in data" :key="item.id">
            <!-- 预留插槽。可以插入想插入的内容，方便 -->
          <slot name="body" :row="item"></slot>
        </tr>
      </tbody>
    </table>
</template>

<script>
export default {
props:{
  data:{
    //   接收数据的类型和方法
    type:Array,
    default: () => []
  }
}
}
</script>

<style lang="less" scoped>
.my-table {
  width: 100%;
  border-spacing: 0;
  img {
    width: 100px;
    height: 100px;
    object-fit: contain;
    vertical-align: middle;
  }
  th {
    background: #f5f5f5;
    border-bottom: 2px solid #069;
  }
  td {
    border-bottom: 1px dashed #ccc;
  }
  td,
  th {
    text-align: center;
    padding: 10px;
    transition: all .5s;
    &.red {
      color: red;
    }
  }
  .none {
    height: 100px;
    line-height: 100px;
    color: #999;
  }
}
</style>